#pragma once

#include <vector>
#include <string>
#include <map>
#include <sfml/Graphics.hpp>
#include "Defines.h"
#include <cassert>

class Visual
{
	friend class VisualPack;
public:
	inline uint16 GetAnimationsCount() const { return m_animationsCount; }
	inline uint16 GetFrames() const { return m_frames; }
	inline sf::Image* GetImage() const { return m_spriteSheet; }
	inline uint16 GetFrameWidth()  const { return m_width;  }
	inline uint16 GetFrameHeight() const { return m_height; }
private:
	void LoadFromFile(const std::string& filename);
	Visual(void);
	~Visual(void);

	uint16 m_animationsCount;				//number of animations(rows)
	uint16 m_width, m_height;				//size of frames
	uint16 m_frames;							//numbers of frames per anim(cols)
	sf::Image* m_spriteSheet;				//pointer to the spritesheet of the current visual
};

class VisualPack 
{
public:
	VisualPack();
	~VisualPack();

	/* Static Functions */
	static VisualPack* GetVisualPack(uint16 guid);
	static VisualPack* GetVisualPack(const std::string& filename);
	static void FreeVisualPack(const std::string& filename);
	static void FreeVisualPack(uint16 guid);
	static inline uint16 GetGuid(const std::string& filename) { return s_filenames.find(filename) == s_filenames.end() ? -1 : s_filenames.find(filename)->second; }
	static const std::string& GetName(uint16 guid);

	/* Member functions */
	inline unsigned GetType() const { return (unsigned)m_visualType; }
	inline unsigned GetVisualsCount() const { return (unsigned)m_visuals.size(); }
	inline void SetCount(uint16 count) { m_count = count; }
	inline uint16 GetCount() const { return m_count; }
	inline Visual* GetVisual(uint16 visual) const 
	{ 
		if(visual > m_visuals.size()) {
			assert(NULL);
			return 0;
		}
		return m_visuals[visual]; 
	}
private:	
	bool LoadFromFile(const std::string& filename);		//Loading seems like it'll be slow.. no worry for now

	uint16 m_count;
	uint16 m_guid;
	uint16 m_visualType;					//building/unit/etc? ..counts on how many visuals to load.
	std::vector<Visual*> m_visuals;			//change this ? no real reason for using a vector.. commodity
	typedef std::map<uint16, VisualPack*> VisualPackMap;
	typedef std::map<std::string, uint16> FilenameMap;

	/* Static Attributes */
	static FilenameMap  s_filenames;
	static VisualPackMap s_visualPacks;
};


